//
//  WalletFlowModel.m
//
//  Created by mac  on 2018/11/29
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "WalletFlowModel.h"


NSString *const kWalletFlowModelAmount = @"Amount";
NSString *const kWalletFlowModelFlowTypeDesc = @"FlowTypeDesc";
NSString *const kWalletFlowModelDirection = @"Direction";
NSString *const kWalletFlowModelCoin = @"Coin";
NSString *const kWalletFlowModelTargetBusinessDesc = @"TargetBusinessDesc";
NSString *const kWalletFlowModelID = @"ID";
NSString *const kWalletFlowModelFlowDate = @"FlowDate";
NSString *const kWalletFlowModelExtraData = @"ExtraData";
NSString *const kWalletFlowModelFlowType = @"FlowType";
NSString *const kWalletFlowModelComment = @"Comment";
NSString *const kWalletFlowModelFlowPayTypeDesc = @"FlowPayTypeDesc";
NSString *const kWalletFlowModelFlowPayType = @"FlowPayType";
NSString *const kWalletFlowModelTargetBusinessID = @"TargetBusinessID";
NSString *const kWalletFlowModelPayReson = @"PayReson";


@interface WalletFlowModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation WalletFlowModel

@synthesize amount = _amount;
@synthesize flowTypeDesc = _flowTypeDesc;
@synthesize direction = _direction;
@synthesize coin = _coin;
@synthesize targetBusinessDesc = _targetBusinessDesc;
@synthesize iDProperty = _iDProperty;
@synthesize flowDate = _flowDate;
@synthesize extraData = _extraData;
@synthesize flowType = _flowType;
@synthesize comment = _comment;
@synthesize flowPayTypeDesc = _flowPayTypeDesc;
@synthesize flowPayType = _flowPayType;
@synthesize targetBusinessID = _targetBusinessID;
@synthesize payReson = _payReson;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.amount = [[self objectOrNilForKey:kWalletFlowModelAmount fromDictionary:dict] doubleValue];
            self.flowTypeDesc = [self objectOrNilForKey:kWalletFlowModelFlowTypeDesc fromDictionary:dict];
            self.direction = [[self objectOrNilForKey:kWalletFlowModelDirection fromDictionary:dict] doubleValue];
            self.coin = [[self objectOrNilForKey:kWalletFlowModelCoin fromDictionary:dict] doubleValue];
            self.targetBusinessDesc = [self objectOrNilForKey:kWalletFlowModelTargetBusinessDesc fromDictionary:dict];
            self.iDProperty = [[self objectOrNilForKey:kWalletFlowModelID fromDictionary:dict] doubleValue];
            self.flowDate = [self objectOrNilForKey:kWalletFlowModelFlowDate fromDictionary:dict];
            self.extraData = [[self objectOrNilForKey:kWalletFlowModelExtraData fromDictionary:dict] doubleValue];
            self.flowType = [[self objectOrNilForKey:kWalletFlowModelFlowType fromDictionary:dict] doubleValue];
            self.comment = [self objectOrNilForKey:kWalletFlowModelComment fromDictionary:dict];
            self.flowPayTypeDesc = [self objectOrNilForKey:kWalletFlowModelFlowPayTypeDesc fromDictionary:dict];
            self.flowPayType = [[self objectOrNilForKey:kWalletFlowModelFlowPayType fromDictionary:dict] doubleValue];
            self.targetBusinessID = [[self objectOrNilForKey:kWalletFlowModelTargetBusinessID fromDictionary:dict] doubleValue];
            self.payReson = [[self objectOrNilForKey:kWalletFlowModelPayReson fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kWalletFlowModelAmount];
    [mutableDict setValue:self.flowTypeDesc forKey:kWalletFlowModelFlowTypeDesc];
    [mutableDict setValue:[NSNumber numberWithDouble:self.direction] forKey:kWalletFlowModelDirection];
    [mutableDict setValue:[NSNumber numberWithDouble:self.coin] forKey:kWalletFlowModelCoin];
    [mutableDict setValue:self.targetBusinessDesc forKey:kWalletFlowModelTargetBusinessDesc];
    [mutableDict setValue:[NSNumber numberWithDouble:self.iDProperty] forKey:kWalletFlowModelID];
    [mutableDict setValue:self.flowDate forKey:kWalletFlowModelFlowDate];
    [mutableDict setValue:[NSNumber numberWithDouble:self.extraData] forKey:kWalletFlowModelExtraData];
    [mutableDict setValue:[NSNumber numberWithDouble:self.flowType] forKey:kWalletFlowModelFlowType];
    [mutableDict setValue:self.comment forKey:kWalletFlowModelComment];
    [mutableDict setValue:self.flowPayTypeDesc forKey:kWalletFlowModelFlowPayTypeDesc];
    [mutableDict setValue:[NSNumber numberWithDouble:self.flowPayType] forKey:kWalletFlowModelFlowPayType];
    [mutableDict setValue:[NSNumber numberWithDouble:self.targetBusinessID] forKey:kWalletFlowModelTargetBusinessID];
    [mutableDict setValue:[NSNumber numberWithDouble:self.payReson] forKey:kWalletFlowModelPayReson];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.amount = [aDecoder decodeDoubleForKey:kWalletFlowModelAmount];
    self.flowTypeDesc = [aDecoder decodeObjectForKey:kWalletFlowModelFlowTypeDesc];
    self.direction = [aDecoder decodeDoubleForKey:kWalletFlowModelDirection];
    self.coin = [aDecoder decodeDoubleForKey:kWalletFlowModelCoin];
    self.targetBusinessDesc = [aDecoder decodeObjectForKey:kWalletFlowModelTargetBusinessDesc];
    self.iDProperty = [aDecoder decodeDoubleForKey:kWalletFlowModelID];
    self.flowDate = [aDecoder decodeObjectForKey:kWalletFlowModelFlowDate];
    self.extraData = [aDecoder decodeDoubleForKey:kWalletFlowModelExtraData];
    self.flowType = [aDecoder decodeDoubleForKey:kWalletFlowModelFlowType];
    self.comment = [aDecoder decodeObjectForKey:kWalletFlowModelComment];
    self.flowPayTypeDesc = [aDecoder decodeObjectForKey:kWalletFlowModelFlowPayTypeDesc];
    self.flowPayType = [aDecoder decodeDoubleForKey:kWalletFlowModelFlowPayType];
    self.targetBusinessID = [aDecoder decodeDoubleForKey:kWalletFlowModelTargetBusinessID];
    self.payReson = [aDecoder decodeDoubleForKey:kWalletFlowModelPayReson];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_amount forKey:kWalletFlowModelAmount];
    [aCoder encodeObject:_flowTypeDesc forKey:kWalletFlowModelFlowTypeDesc];
    [aCoder encodeDouble:_direction forKey:kWalletFlowModelDirection];
    [aCoder encodeDouble:_coin forKey:kWalletFlowModelCoin];
    [aCoder encodeObject:_targetBusinessDesc forKey:kWalletFlowModelTargetBusinessDesc];
    [aCoder encodeDouble:_iDProperty forKey:kWalletFlowModelID];
    [aCoder encodeObject:_flowDate forKey:kWalletFlowModelFlowDate];
    [aCoder encodeDouble:_extraData forKey:kWalletFlowModelExtraData];
    [aCoder encodeDouble:_flowType forKey:kWalletFlowModelFlowType];
    [aCoder encodeObject:_comment forKey:kWalletFlowModelComment];
    [aCoder encodeObject:_flowPayTypeDesc forKey:kWalletFlowModelFlowPayTypeDesc];
    [aCoder encodeDouble:_flowPayType forKey:kWalletFlowModelFlowPayType];
    [aCoder encodeDouble:_targetBusinessID forKey:kWalletFlowModelTargetBusinessID];
    [aCoder encodeDouble:_payReson forKey:kWalletFlowModelPayReson];
}

- (id)copyWithZone:(NSZone *)zone
{
    WalletFlowModel *copy = [[WalletFlowModel alloc] init];
    
    if (copy) {

        copy.amount = self.amount;
        copy.flowTypeDesc = [self.flowTypeDesc copyWithZone:zone];
        copy.direction = self.direction;
        copy.coin = self.coin;
        copy.targetBusinessDesc = [self.targetBusinessDesc copyWithZone:zone];
        copy.iDProperty = self.iDProperty;
        copy.flowDate = [self.flowDate copyWithZone:zone];
        copy.extraData = self.extraData;
        copy.flowType = self.flowType;
        copy.comment = [self.comment copyWithZone:zone];
        copy.flowPayTypeDesc = [self.flowPayTypeDesc copyWithZone:zone];
        copy.flowPayType = self.flowPayType;
        copy.targetBusinessID = self.targetBusinessID;
        copy.payReson = self.payReson;
    }
    
    return copy;
}


@end
